package org.apaydin.eksisozluk;

import java.util.ArrayList;
import java.util.List;

public class EksiTopics{

    private List<EksiTopic> topics = new ArrayList<EksiTopic>();

    private int topicCount = 0;

    private int pageCount = 0;

    private int currentPage = 0;

    private final String keyword;

    private final TopicFetcherImpl fetcher;

    public EksiTopics(String keyword) {
        this.keyword = keyword;
        fetcher = new TopicFetcherImpl(keyword);
    }

    public void addItem(EksiTopic topic){
        topics.add(topic);
    }

    public List<EksiTopic> getTopics() {
        return topics;
    }

    public int getTopicCount() {
        return topicCount;
    }

    public void setTopicCount(int topicCount) {
        this.topicCount = topicCount;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public String getKeyword() {
        return keyword;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    @Override
    public String toString() {
        return "EksiTopics{" +
                "keyword='" + keyword + '\'' +
                ", topicCount=" + topicCount +
                ", pageCount=" + pageCount +
                ", currentPage=" + currentPage +
                ", topics=" + topics +
                '}';
    }

    public void fetch(int page){
        try {
            fetcher.fetch(this, page);
        } catch (Exception e) {
            throw new EksiException(e.getMessage(), e);
        }
    }


    public EksiTopic get(int index) {
        return getTopics().get(index);
    }
}
